package xiaoqi.springboot.log.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import xiaoqi.springboot.log.helper.ExceptionHelper;
import xiaoqi.springboot.log.mapper.UserMapper;
import xiaoqi.springboot.log.service.MyServiceImpl;

import java.time.LocalDateTime;

@RestController
@RequestMapping("/log")
public class LogController {

    private static final Logger logger = LoggerFactory.getLogger(LogController.class);

    @Autowired
    private MyServiceImpl myService;
    @Autowired
    private ExceptionHelper exceptionHelper;
    @Autowired
    private UserMapper userMapper;

    @RequestMapping("/index")
    public ResponseEntity index() {
        logger.info("index");
        logger.error("index-error");
        myService.doSth("hhhh");
        return new ResponseEntity(LocalDateTime.now(), HttpStatus.OK);
    }


    @RequestMapping("error")
    public ResponseEntity exp() {
        logger.error("before");
//        exceptionHelper.throwException();
        logger.error("after");
        return new ResponseEntity(LocalDateTime.now(), HttpStatus.OK);
    }

}
